home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / fpoly256.zip / DEMOX3D.C next >
C/C++ Source or Header  |  1992-01-27  |  4KB  |  234 lines

  1. #include <bios.h>
  2. #include <dos.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <graphics.h>
  7. #include <math.h>
  8.  
  9. #include "fx3dkit.h"
  10.  
  11.  
  12.  
  13. /****************** TEST/DEMO SOFTWARE ******************/
  14.  
  15.  
  16.      /* defined keystrokes for the program */
  17. enum key{ null=0,
  18.       F1,
  19.       F2,
  20.       F3,
  21.       F4,
  22.       home,
  23.       end,
  24.       up_arrow,
  25.       down_arrow,
  26.       left_arrow,
  27.       right_arrow,
  28.       esc,
  29.       enter,
  30.       backspace,
  31.       plus,
  32.       minus,
  33.     };
  34.  
  35.  
  36.             /* GET KEY COMMAND */
  37. enum key getkey()
  38. {
  39.  int c;
  40.  
  41.  if (!kbhit()) return(null);    /* null if no key hit */
  42.  
  43.  c = (int) getch();             /* get key code */
  44.  if (c)                         /* nonzero key code */
  45.    {
  46.     switch(c)                   /* return proper name */
  47.       {
  48.        case 27:  return(esc);
  49.        case 13:  return(enter);
  50.        case 8:   return(backspace);
  51.        case '+': return(plus);
  52.        case '-': return(minus);
  53.        default: return(c);       /* ASCII if not command */
  54.       }
  55.    }
  56.  
  57.  c = (int) getch();        /* zero code: get second byte */
  58.  switch(c)            /* return proper name */
  59.    {
  60.     case 59: return(F1);
  61.     case 60: return(F2);
  62.     case 61: return(F3);
  63.     case 62: return(F4);
  64.     case 71: return(home);
  65.     case 79: return(end);
  66.     case 72: return(up_arrow);
  67.     case 80: return(down_arrow);
  68.     case 75: return(left_arrow);
  69.     case 77: return(right_arrow);
  70.     default: return(c);         /* ASCII if not command */
  71.    }
  72. }
  73.  
  74.  
  75. void dummy(int a, int b, int c, int d, int e)
  76. {
  77. return;
  78. }
  79.  
  80.  
  81.  
  82. #define INC 4        /* number degrees per step for THING demo */
  83.  
  84. main()
  85. {
  86.  long btime;
  87.  float mtime;
  88.  int i,j,k;
  89.  int x[4],y[4];
  90.  char c;
  91.  lpoints l;
  92.  
  93.  set_gmode();
  94.  set_vidpage(0,0);
  95.  set_drawpage(0);
  96.  
  97.   goto speedtri; /* test tri/quad/line time */
  98. /*  goto grest;    /* test line drawing and clipping */
  99.  
  100.  
  101. demo:
  102.  j=0;
  103.  k=180;
  104.  i = 0;
  105.  set_drawpage(2);
  106.  clr_page(2,2);
  107.  setup_hdwe(PUT);
  108.  poly3(20,20,160,60,160,140,4);
  109.  poly3(300,180,160,60,160,140,3);
  110.  c=0;
  111.  
  112. doit:
  113.  set_vidpage(i^1,1);
  114.  copy_page(2,i);
  115. /* clr_page(i,0); */
  116.  set_drawpage(i);
  117.  i = i^1;
  118.  setup_hdwe(PUT);
  119.  draw_thing(j,k);
  120.  reset_hdwe();
  121.  if(getkey()==esc)exit(0);
  122.  if(c==1)
  123.   {
  124.    j+=INC;
  125.    k-=INC;
  126.    if(j>=90) c = c^1;
  127.   }
  128.  if(c==0)
  129.   {
  130.    j-=INC;
  131.    k+=INC;
  132.    if(j<=-90)c = c^1;
  133.   }
  134.  goto doit;
  135.  
  136. grest:
  137.  t_clip = l_clip = 25;
  138.  b_clip = r_clip = 175;
  139.  
  140.  set_drawpage(2);
  141.  clr_page(2,0);
  142.  setup_hdwe(PUT);
  143.  poly4(l_clip,t_clip,l_clip,b_clip,r_clip,t_clip,r_clip,b_clip,4);
  144.  
  145. grept:
  146.  set_vidpage(0,1);
  147.  copy_page(2,0);
  148.  set_drawpage(0);
  149.  setup_hdwe(PUT);
  150.  for(i=0;i<2;i++)
  151.   {
  152.    x[i] = random(100);
  153.    y[i] = random(100);
  154.    if(x[i]>50) x[i] +=100;
  155.    if(y[i]>50) y[i] +=100;
  156.    l.x1 = x[i]; l.x2 = x[i]+1;
  157.    l.y1 = y[i]; l.y2 = y[i];
  158.    vgalines(&l,13+i);
  159.   }
  160.    l.x1 = x[0]; l.x2 = x[1];
  161.    l.y1 = y[0]; l.y2 = y[1];
  162.  if(toupper(getch())=='N') goto grept;
  163.  setup_hdwe(PUT);
  164.  if(clipper(&l)!=-1)
  165.    vgalines(&l,15);
  166.  reset_hdwe();
  167.  if(toupper(getch())=='R')
  168.   {
  169.    setup_hdwe(PUT);
  170.    l.x1 = x[0]; l.x2 = x[1];
  171.    l.y1 = y[0]; l.y2 = y[1];
  172.    if(clipper(&l)!=-1)
  173.      vgalines(&l,15);
  174.    reset_hdwe();
  175.   }
  176.  goto grept;
  177.  
  178. speedtri:
  179.  setup_hdwe(PUT);
  180.                    /* draw 49300 24x24 trapezoids */
  181.  reset_hdwe();
  182.  
  183.  btime = biostime(0,0L);
  184.  
  185.  setup_hdwe(PUT);
  186.  for(i=0;i<290;i++)
  187.  for(k=0;k<170;k++)
  188. /*
  189.   poly4(i+10, k, i, k+4, i+3, k+4, i+20, k+30, ((i+k)%15)+1);
  190. */
  191. /*
  192.  poly3(i+10, k, i, k+4, i+3, k+4, (i+k)&255);
  193. */
  194.  
  195.  for(j=0;j<10;j++) vgaline(i,k,i+22,k+20,(i+k)&255);
  196.  
  197. /*
  198.  {
  199.   load_color((i+k)&255);
  200.   fastri(i+10,k,i,k+4,i+3,k+4);
  201.  }
  202. */
  203.  reset_hdwe();
  204.  exit_gmode();
  205.  printf("Time for 49300(0) Draws: %f\n", (float)(biostime(0,0L)-btime)/18.2);
  206.  btime = biostime(0,0L);
  207.  
  208.  getch();
  209.  reset_hdwe();
  210.  exit_gmode();
  211. }
  212.  
  213.  
  214. draw_thing(j,k)
  215. {
  216.  int x1,x2,y1,y2;
  217.  float snj=sin(j/57.3);
  218.  float snk=sin(k/57.3);
  219.  float csj=cos(j/57.3);
  220.  float csk=cos(k/57.3);
  221.  
  222.  x1 = 66*csj+160;
  223.  x2 = 66*csk+160;
  224.  y1 = 66*snj+70;
  225.  y2 = 66*snk+70;
  226.  
  227.  poly3(10,10,160,100,x2,y2,12);
  228.  poly3(310,10,160,100,x1,y1,13);
  229.  poly3(160,190,x1,y1,x2,y2,14);
  230.  poly3(160,100,x1,y1,x2,y2,15);
  231. }
  232.  
  233.  
  234.